package string.easy;

public class LeetCode520 {
    public boolean detectCapitalUse1(String word) {
        if (word.length()==1) return true;
        boolean firsCharLower = Character.isLowerCase(word.charAt(0));
        if (firsCharLower) {
            for (int i = 1; i < word.length(); i++) {
                if (!Character.isLowerCase(word.charAt(i))) {
                    return false;
                }
            }
        } else {
            boolean secondCharLower = Character.isLowerCase(word.charAt(1));
            for (int i = 1; i < word.length(); i++) {
                if (Character.isLowerCase(word.charAt(i)) != secondCharLower) {
                    return false;
                }
            }
        }
        return true;
    }

    /**
     * 统计数量
     * @param word
     * @return
     */
    public boolean detectCapitalUse(String word) {
        int lowerCase = 0;
        for (int i = 0; i < word.length(); i++) {
            if (Character.isLowerCase(word.charAt(i))) {
                lowerCase++;
            }
        }
        int upperCase = word.length() - lowerCase;
        if (lowerCase == word.length()) {
            return true;
        }
        if (upperCase == word.length()) {
            return true;
        }
        if (upperCase == 1 && Character.isUpperCase(word.charAt(0))) {
            return true;
        }
        return false;
    }
}
